home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / apel / emu-18.el.z / emu-18.el
Encoding:
Text File  |  1998-05-21  |  10.2 KB  |  367 lines

  1. ;;; emu-18.el --- emu API implementation for Emacs 18.*
  2.  
  3. ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
  4.  
  5. ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
  6. ;; Version: $Id: emu-18.el,v 7.33 1997/04/05 06:44:01 morioka Exp $
  7. ;; Keywords: emulation, compatibility
  8.  
  9. ;; This file is part of emu.
  10.  
  11. ;; This program is free software; you can redistribute it and/or
  12. ;; modify it under the terms of the GNU General Public License as
  13. ;; published by the Free Software Foundation; either version 2, or (at
  14. ;; your option) any later version.
  15.  
  16. ;; This program is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  23. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26. ;;; Code:
  27.  
  28. (autoload 'setenv "env"
  29.   "Set the value of the environment variable named VARIABLE to VALUE.
  30. VARIABLE should be a string.  VALUE is optional; if not provided or is
  31. `nil', the environment variable VARIABLE will be removed.  
  32. This function works by modifying `process-environment'."
  33.   t)
  34.  
  35. (defvar data-directory exec-directory)
  36.  
  37.  
  38. ;;; @ for EMACS 18.55
  39. ;;;
  40.  
  41. (defvar buffer-undo-list nil)
  42.  
  43.  
  44. ;;; @ hook
  45. ;;;
  46.  
  47. ;; These function are imported from EMACS 19.28.
  48. (defun add-hook (hook function &optional append)
  49.   "Add to the value of HOOK the function FUNCTION.
  50. FUNCTION is not added if already present.
  51. FUNCTION is added (if necessary) at the beginning of the hook list
  52. unless the optional argument APPEND is non-nil, in which case
  53. FUNCTION is added at the end.
  54.  
  55. HOOK should be a symbol, and FUNCTION may be any valid function.  If
  56. HOOK is void, it is first set to nil.  If HOOK's value is a single
  57. function, it is changed to a list of functions.
  58. \[emu-18.el; EMACS 19 emulating function]"
  59.   (or (boundp hook)
  60.       (set hook nil)
  61.       )
  62.   ;; If the hook value is a single function, turn it into a list.
  63.   (let ((old (symbol-value hook)))
  64.     (if (or (not (listp old))
  65.         (eq (car old) 'lambda))
  66.     (set hook (list old))
  67.       ))
  68.   (or (if (consp function)
  69.       ;; Clever way to tell whether a given lambda-expression
  70.       ;; is equal to anything in the hook.
  71.       (let ((tail (assoc (cdr function) (symbol-value hook))))
  72.         (equal function tail)
  73.         )
  74.     (memq function (symbol-value hook))
  75.     )
  76.       (set hook 
  77.        (if append
  78.            (nconc (symbol-value hook) (list function))
  79.          (cons function (symbol-value hook))
  80.          ))
  81.       ))
  82.  
  83. (defun remove-hook (hook function)
  84.   "Remove from the value of HOOK the function FUNCTION.
  85. HOOK should be a symbol, and FUNCTION may be any valid function.  If
  86. FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
  87. list of hooks to run in HOOK, then nothing is done.  See `add-hook'.
  88. \[emu-18.el; EMACS 19 emulating function]"
  89.   (if (or (not (boundp hook))        ;unbound symbol, or
  90.       (null (symbol-value hook))    ;value is nil, or
  91.       (null function))        ;function is nil, then
  92.       nil                ;Do nothing.
  93.     (let ((hook-value (symbol-value hook)))
  94.       (if (consp hook-value)
  95.       (setq hook-value (delete function hook-value))
  96.     (if (equal hook-value function)
  97.         (setq hook-value nil)
  98.       ))
  99.       (set hook hook-value)
  100.       )))
  101.  
  102.  
  103. ;;; @ list
  104. ;;;
  105.  
  106. (defun member (elt list)
  107.   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
  108. The value is actually the tail of LIST whose car is ELT.
  109. \[emu-18.el; EMACS 19 emulating function]"
  110.   (while (and list (not (equal elt (car list))))
  111.     (setq list (cdr list)))
  112.   list)
  113.  
  114. (defun delete (elt list)
  115.   "Delete by side effect any occurrences of ELT as a member of LIST.
  116. The modified LIST is returned.  Comparison is done with `equal'.
  117. If the first member of LIST is ELT, deleting it is not a side effect;
  118. it is simply using a different list.
  119. Therefore, write `(setq foo (delete element foo))'
  120. to be sure of changing the value of `foo'.
  121. \[emu-18.el; EMACS 19 emulating function]"
  122.   (if (equal elt (car list))
  123.       (cdr list)
  124.     (let ((rest list)
  125.       (rrest (cdr list))
  126.       )
  127.       (while (and rrest (not (equal elt (car rrest))))
  128.     (setq rest rrest
  129.           rrest (cdr rrest))
  130.     )
  131.       (rplacd rest (cdr rrest))
  132.       list)))
  133.  
  134.  
  135. ;;; @ function
  136. ;;;
  137.  
  138. (defun defalias (sym newdef)
  139.   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
  140. Associates the function with the current load file, if any.
  141. \[emu-18.el; EMACS 19 emulating function]"
  142.   (fset sym newdef)
  143.   )
  144.  
  145. (defun byte-code-function-p (exp)
  146.   "T if OBJECT is a byte-compiled function object.
  147. \[emu-18.el; EMACS 19 emulating function]"
  148.   (and (consp exp)
  149.        (let* ((rest (cdr (cdr exp))) elt)
  150.      (if (stringp (car rest))
  151.          (setq rest (cdr rest))
  152.        )
  153.      (catch 'tag
  154.        (while rest
  155.          (setq elt (car rest))
  156.          (if (and (consp elt)(eq (car elt) 'byte-code))
  157.          (throw 'tag t)
  158.            )
  159.          (setq rest (cdr rest))
  160.          ))
  161.      )))
  162.  
  163. (defmacro-maybe defsubst (name arglist &rest body)
  164.   "Define an inline function.  The syntax is just like that of `defun'."
  165.   (cons 'defun (cons name (cons arglist body)))
  166.   )
  167.  
  168.  
  169. ;;; @ file
  170. ;;;
  171.  
  172. (defun make-directory-internal (dirname)
  173.   "Create a directory. One argument, a file name string.
  174. \[emu-18.el; EMACS 19 emulating function]"
  175.   (if (file-exists-p dirname)
  176.       (error "Creating directory: %s is already exist" dirname)
  177.     (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
  178.     (error "Creating directory: no such file or directory, %s" dirname)
  179.       )))
  180.  
  181. (defun make-directory (dir &optional parents)
  182.   "Create the directory DIR and any nonexistent parent dirs.
  183. The second (optional) argument PARENTS says whether
  184. to create parent directories if they don't exist.
  185. \[emu-18.el; EMACS 19 emulating function]"
  186.   (let ((len (length dir))
  187.     (p 0) p1 path)
  188.     (catch 'tag
  189.       (while (and (< p len) (string-match "[^/]*/?" dir p))
  190.     (setq p1 (match-end 0))
  191.     (if (= p1 len)
  192.         (throw 'tag nil)
  193.       )
  194.     (setq path (substring dir 0 p1))
  195.     (if (not (file-directory-p path))
  196.         (cond ((file-exists-p path)
  197.            (error "Creating directory: %s is not directory" path)
  198.            )
  199.           ((null parents)
  200.            (error "Creating directory: %s is not exist" path)
  201.            )
  202.           (t
  203.            (make-directory-internal path)
  204.            ))
  205.       )
  206.     (setq p p1)
  207.     ))
  208.     (make-directory-internal dir)
  209.     ))
  210.  
  211. ;; Imported from files.el of EMACS 19.33.
  212. (defun parse-colon-path (cd-path)
  213.   "Explode a colon-separated list of paths into a string list."
  214.   (and cd-path
  215.        (let (cd-prefix cd-list (cd-start 0) cd-colon)
  216.      (setq cd-path (concat cd-path path-separator))
  217.      (while (setq cd-colon (string-match path-separator cd-path cd-start))
  218.        (setq cd-list
  219.          (nconc cd-list
  220.             (list (if (= cd-start cd-colon)
  221.                    nil
  222.                 (substitute-in-file-name
  223.                  (file-name-as-directory
  224.                   (substring cd-path cd-start cd-colon)))))))
  225.        (setq cd-start (+ cd-colon 1)))
  226.      cd-list)))
  227.  
  228. ;; Imported from files.el of EMACS 19.33.
  229. (defun file-relative-name (filename &optional directory)
  230.   "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
  231.   (setq filename (expand-file-name filename)
  232.     directory (file-name-as-directory (expand-file-name
  233.                        (or directory default-directory))))
  234.   (let ((ancestor ""))
  235.     (while (not (string-match (concat "^" (regexp-quote directory)) filename))
  236.       (setq directory (file-name-directory (substring directory 0 -1))
  237.         ancestor (concat "../" ancestor)))
  238.     (concat ancestor (substring filename (match-end 0)))))
  239.  
  240. (or (fboundp 'si:directory-files)
  241.     (fset 'si:directory-files (symbol-function 'directory-files)))
  242. (defun directory-files (directory &optional full match nosort)
  243.   "Return a list of names of files in DIRECTORY.
  244. There are three optional arguments:
  245. If FULL is non-nil, return absolute file names.  Otherwise return names
  246.  that are relative to the specified directory.
  247. If MATCH is non-nil, mention only file names that match the regexp MATCH.
  248. If NOSORT is dummy for compatibility.
  249. \[emu-18.el; EMACS 19 emulating function]"
  250.   (si:directory-files directory full match)
  251.   )
  252.  
  253.     
  254. ;;; @ mark
  255. ;;;
  256.  
  257. (or (fboundp 'si:mark)
  258.     (fset 'si:mark (symbol-function 'mark)))
  259. (defun mark (&optional force)
  260.   (si:mark)
  261.   )
  262.  
  263.  
  264. ;;; @ mode-line
  265. ;;;
  266.  
  267. ;;; Imported from Emacs 19.30.
  268. (defun force-mode-line-update (&optional all)
  269.   "Force the mode-line of the current buffer to be redisplayed.
  270. With optional non-nil ALL, force redisplay of all mode-lines.
  271. \[emu-18.el; Emacs 19 emulating function]"
  272.   (if all (save-excursion (set-buffer (other-buffer))))
  273.   (set-buffer-modified-p (buffer-modified-p)))
  274.  
  275.  
  276. ;;; @ overlay
  277. ;;;
  278.  
  279. (defun overlay-buffer (overlay))
  280.  
  281.  
  282. ;;; @ text property
  283. ;;;
  284.  
  285. (defun remove-text-properties (start end properties &optional object))
  286.  
  287.  
  288. ;;; @@ visible/invisible
  289. ;;;
  290.  
  291. (defmacro enable-invisible ()
  292.   (`
  293.    (progn
  294.      (make-local-variable 'original-selective-display)
  295.      (setq original-selective-display selective-display)
  296.      (setq selective-display t)
  297.      )))
  298.  
  299. (defmacro end-of-invisible ()
  300.   (` (setq selective-display
  301.        (if (boundp 'original-selective-display)
  302.            original-selective-display))
  303.      ))
  304.  
  305. (defun invisible-region (start end)
  306.   (let ((buffer-read-only nil)        ;Okay even if write protected.
  307.     (modp (buffer-modified-p)))
  308.     (if (save-excursion
  309.       (goto-char (1- end))
  310.       (eq (following-char) ?\n)
  311.       )
  312.     (setq end (1- end))
  313.       )
  314.     (unwind-protect
  315.         (subst-char-in-region start end ?\n ?\^M t)
  316.       (set-buffer-modified-p modp)
  317.       )))
  318.  
  319. (defun visible-region (start end)
  320.   (let ((buffer-read-only nil)        ;Okay even if write protected.
  321.     (modp (buffer-modified-p)))
  322.     (unwind-protect
  323.         (subst-char-in-region start end ?\^M ?\n t)
  324.       (set-buffer-modified-p modp)
  325.       )))
  326.  
  327. (defun invisible-p (pos)
  328.   (save-excursion
  329.     (goto-char pos)
  330.     (eq (following-char) ?\^M)
  331.     ))
  332.  
  333. (defun next-visible-point (pos)
  334.   (save-excursion
  335.     (goto-char pos)
  336.     (end-of-line)
  337.     (if (eq (following-char) ?\n)
  338.     (forward-char)
  339.       )
  340.     (point)
  341.     ))
  342.  
  343.  
  344. ;;; @ mouse
  345. ;;;
  346.  
  347. (defvar mouse-button-1 nil)
  348. (defvar mouse-button-2 nil)
  349. (defvar mouse-button-3 nil)
  350.  
  351.  
  352. ;;; @ string
  353. ;;;
  354.  
  355. (defun char-list-to-string (char-list)
  356.   "Convert list of character CHAR-LIST to string. [emu-18.el]"
  357.   (mapconcat (function char-to-string) char-list "")
  358.   )
  359.  
  360.  
  361. ;;; @ end
  362. ;;;
  363.  
  364. (provide 'emu-18)
  365.  
  366. ;;; emu-18.el ends here
  367.